package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.pojo.PageInfo;
import com.example.demo.pojo.User;
import com.example.demo.service.AfterUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("afterUser")
@Api(value = "用户管理",tags = "用户管理")
public class AfterUserController {
    @Resource
    private AfterUserService afterUserService;

    @RequestMapping(value = "/deleteByPrimaryKey",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除用户",notes = "删除用户")
    @ApiImplicitParams({@ApiImplicitParam(name = "userid",value = "用户id")})
    public String deleteByPrimaryKey(Integer userid){
        int res=afterUserService.deleteByPrimaryKey(userid);
        return JSON.toJSONString(res);
    }


    @RequestMapping(value = "/getAll",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "查询所有用户",notes = "查询所有用户")
    public String getAll(@RequestParam(defaultValue = "1",value = "currentPage") Integer pageNum,
                         @RequestParam(defaultValue = "1",value = "pageSize") Integer pageSize){
        Page<User> user=afterUserService.getAll(pageNum,pageSize);
        com.github.pagehelper.PageInfo<User> pageInfo=new com.github.pagehelper.PageInfo<>(user);
        return JSON.toJSONString(pageInfo);
    }
    @ResponseBody
    @RequestMapping(value = "/updateByPrimaryKey",method = RequestMethod.POST)
    @ApiOperation(value = "修改用户",notes = "修改用户")
    @ApiImplicitParams({@ApiImplicitParam(name = "phonenumber",value = "手机号"),
            @ApiImplicitParam(name = "balance",value = "账户余额"),
            @ApiImplicitParam(name = "name",value = "用户名称"),
            @ApiImplicitParam(name = "integral",value = "用户积分"),
            @ApiImplicitParam(name = "paymentpassword",value = "交易密码"),
            @ApiImplicitParam(name = "member",value = "会员标识")
    })
    public String updateByPrimaryKey(User record){
        int res=afterUserService.updateByPrimaryKey(record);
        return JSON.toJSONString(res);
    }
}
